package j20251115;

import java.io.File;

public class FileWay {
    public static void main(String[] args) {
        // 1. 通过路径字符串创建
        File file1 = new File("j20251117/test.txt");
        System.out.println("文件1: " + file1.getPath());

        // 2. 通过父路径和子路径创建
        File file2 = new File("/home/user", "documents/file.txt");
        System.out.println("文件2: " + file2.getPath());

        // 3. 通过父File对象和子路径创建
        File parentDir = new File("/home/user");
        File file3 = new File(parentDir, "documents/file.txt");
        System.out.println("文件3: " + file3.getPath());

        // 4. 通过URI创建
        try {
            java.net.URI uri = new java.net.URI("file:///home/user/test.txt");
            File file4 = new File(uri);
            System.out.println("文件4: " + file4.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
